﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bussiness;

namespace WebApplication.Admin
{
    public partial class BaoCaoTheoNhaCungCap : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadNhaCungCap();
            }

        }
        public void LoadNhaCungCap()
        {
            IUnitOfWork iunitfwork = new EFUnitOfWork();
            NHACUNGCAPRepository repository=new NHACUNGCAPRepository(new EFRepository<NHACUNGCAP>(),iunitfwork);
            IQueryable<NHACUNGCAP> objnhacungcap=repository.All();
            Dlnhacc.DataSource=objnhacungcap;
            Dlnhacc.DataValueField="MANCC";
            Dlnhacc.DataTextField="TENNCC";
            Dlnhacc.DataBind();
            Dlnhacc.Items.Insert(0,new ListItem{Text="---Chọn nhà cung cấp---",Value="0"});
        }

        protected void lbtnxem_Click(object sender, EventArgs e)
        {
            DateTime dt = Commomcs.convertDate(datepicker.Text);
            if (Dlnhacc.SelectedValue.Equals("0"))
            {
                RegisterClientScriptBlock("Thông báo", "<Script> alert('Vui lòng chọn nhà cung cấp')</script>");
                return;
            }
            if (!string.IsNullOrEmpty(datepicker.Text))
            { 

                string ngay=dt.ToString("dd/MM/yyyy");
                string strmancc=Dlnhacc.SelectedValue;
                var source = new Microsoft.Reporting.WebForms.ReportDataSource("BaoCaoTheoNhaCungCap", new Baocao.BaoCaoTheoNhaCungCap().GetBaoCaoNhap(dt, ngay, strmancc));
                ReportViewer1.LocalReport.ReportPath=@"Admin\Baocao\BaoCaoTheoNhaCungCap.rdlc";
                ReportViewer1.LocalReport.DataSources.Clear();
                ReportViewer1.LocalReport.DataSources.Add(source);
                ReportViewer1.LocalReport.Refresh();
            }
        }
    }
}